<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>登录</title>
		<!-- 样 式 文 件 -->
		<link rel="stylesheet" href="component/pear/css/pear.css" />
		<link rel="stylesheet" href="admin/css/other/login.css" />
	</head>
    <!-- 代 码 结 构 -->
	<body background="admin/images/background.svg" style="background-size: cover;">
	<div class="layui-layout layui-layout-admin">
		<div class="layui-header layui-hide">

		</div>
		<div class="layui-body" style="left: 0;">
			<form class="layui-form" action="javascript:void(0);" lay-filter="form-login">
				<div class="layui-form-item">
					<img class="logo" src="admin/images/logo.png" />
					<div class="title">www.aday.fun</div>
					<div class="desc">
						开心，是一种生活态度。
					</div>
				</div>
				<div class="layui-form-item">
					<input type="text" placeholder="账 户 :" name="username" value="guest" autocomplete="new-password" lay-verify="required|username" hover class="layui-input"  />
				</div>
				<div class="layui-form-item">
					<input type="password" placeholder="密 码 :" name="password" value="123456" autocomplete="new-password" lay-verify="required|password" hover class="layui-input"  />
				</div>
				<div class="layui-form-item layui-hide">
					<input placeholder="验证码 :" name="captcha" hover class="code layui-input layui-input-inline"  />
					<img src="admin/images/captcha.gif" class="codeImage" />
				</div>
				<div class="layui-form-item">
					<input type="checkbox" name="rememberMe" title="记住密码" lay-skin="primary">
				</div>
				<div class="layui-form-item">
					<button type="button" name="login" class="pear-btn pear-btn-success login" lay-submit lay-filter="login-btn">
						登 入
					</button>
				</div>
			</form>
		</div>

		<div class="layui-footer layui-text" style="left: 0; text-align: center;">
			<span class="center">
					<a href="www.aday.fun">www.aday.fun</a> Meng Wei Jin <a href="https://beian.miit.gov.cn" target="_blank">陕ICP备2022013125号</a> Copyright © 2018~<span id="footerNowYear"></span> <a href="mailto:mengweijin.work@foxmail.com">mengweijin.work@foxmail.com</a>
					The MIT license.
			</span>
		</div>
	</div>







		<!-- 资 源 引 入 -->
		<script src="component/layui/layui.js"></script>
		<script src="component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'jquery'], function() {
				var form = layui.form;
				var $ = layui.jquery;

				// 自定义验证规则，如下以验证用户名和密码为例
                form.verify({
                    // 函数写法。参数 value 为表单的值；参数 item 为表单的 DOM 对象
                    username: function(value, item){
                      if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){ return '用户名不能有特殊字符'; }
                      if(/(^_)|(__)|(_+$)/.test(value)) { return '用户名首尾不能出现 _ 下划线'; }
                      if(/^\d+$/.test(value)) { return '用户名不能全为数字'; }
                      if(value.length < 4){ return '用户名至少4位！'; }
                    },
                    // 数组写法。数组中两个成员值分别代表：[正则表达式、正则匹配不符时的提示文字]
                    password: [/^[\S]{6,20}$/, '密码必须为6到20位的非空字符']
                });

				form.on('submit(login-btn)', function(data) {
					data.field.rememberMe = data.field.rememberMe == 'on' ? true : false;
					$.ajax({
                        url: '/login',
                        async: false,
                        method: 'post',
                        data: data.field,
                        success: function(result){
                        	if (result.code == 200) {
								top.window.location.href = 'index.html';
							}
                        },
                        complete: function(xhr, textStatus){
                        	if(xhr.status != 200) {
                        		$.get('/captcha', function(captcha) {
                        			console.log(captcha);
                        			$('.codeImage').attr('src', captcha).parent().removeClass('layui-hide');
                        			$('form input[name=captcha]').attr('lay-verify', 'required');
                        		});
                        	}
                        }
                    });

					return false;
				});

				$(document).keyup(function(event){
                	if(event.keyCode ==13){
                		$('form button[name=login]').click();
                	}
                });

                $("#footerNowYear").text(new Date().getFullYear());
			})
		</script>
	</body>
</html>
